package com.itheima.controller;

import com.itheima.pojo.Dept;
import com.itheima.pojo.Result;
import com.itheima.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 部门管理
 */
//相当于下面的Logger对象
@Slf4j
@RestController
public class DeptController {

    /**
     * @Slf4j
     * 加上Slf4j注解，就可以省去这个日志对象，直接调用log方法
     * slf4j下的Logger
     * private static Logger log = LoggerFactory.getLogger(DeptController.class);
     */

    /*
        这段语法其实就相当于@GetMapping
        @RequestMapping(value = "/depts",method = RequestMethod.GET)//指定请求方式为GET
     */

            //注入
    @Autowired
    private DeptService deptService;

    @GetMapping("/depts")
    public Result list() {
        log.info("查询全部部门数据");

        //调用service来查询部门数据
        List<Dept> deptList = deptService.list();


        return Result.success(deptList);
    }
}
